<template>
  <div>
    <el-dialog :title="title" :visible.sync="visible" width="600px" append-to-body :destroy-on-close="true">
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="人事关系" prop="name">
          <el-select v-model="form.selectedList" placeholder="请选择">
            <el-option v-for="item in userRelationList" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm"> 保 存</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRelation } from '@/api/project/user-relation'

export default {
  name: 'UserRelationModal',
  data() {
    return {
      title: '人事关系配置',
      visible: false,
      form: {
        selectedList: '',
        formKey: '',
        id: '',
        evaluated: '',
        userRelationName: ''
      },
      userRelationList: [],
      buttonLoading: false
    }
  },
  methods: {
    getUserRelationList() {
      listRelation(this.form.formKey, {}).then((res) => {
        console.log(res)
        this.userRelationList = res.data.records
      })
    },
    // add() {
    //     this.visible = true
    //     this.getUserRelationList()
    // },
    update() {
      this.visible = true
      this.getUserRelationList()
    },
    submitForm() {
      let selected = this.form.selectedList
      for (let e of this.userRelationList) {
        if (e.id == selected) {
          this.form.userRelationName = e.name
          break
        }
      }
      console.log(this.form)
      this.$emit('ok', this.form)
      this.visible = false
    },
    cancel() {
      this.resetForm('form')
      this.visible = false
    }
  }
}
</script>

<style scoped></style>
